package btp.Calendars;

public class CopticCalendar {
	//Christian copts are the modern descendants of the Pharaonic Egyptian. They use a similar calendar, but with leap years.
	//Year starts late summer, day begins at sunset. The calendar has 12 months of 30 days each with an extra period of 5 or 6 days.
	//Leap years are every 4 years.
	
	
	//Epoch at 29, August 284 CE(Julian) at 1 AM.
	public static final long EPOCH = JulianCalendar.getRDFromJulian(284, JulianCalendar.AUGUST, 29);
	
	//Months
	public static final int THOOUT = 1;
	public static final int PAOPE = 2;
	public static final int ATHOR = 3;
	public static final int KOIAK = 4;
	public static final int TOBE = 5;
	public static final int MESHIR = 6;
	public static final int PAREMOTEP = 7;
	public static final int PARMOUTE = 8;
	public static final int PARSHONS = 9;
	public static final int PAONE = 10;
	public static final int EPEP = 11;
	public static final int MESORE = 12;
	public static final int EPAGOMENE = 13;
	
//	Days
	public static final int TKYRIAKE = 0;
	public static final int PESNAU = 1;
	public static final int PSHOMENT = 2;
	public static final int PEFTOOU = 3;
	public static final int PTIOU = 4;
	public static final int PSOOU = 5;
	public static final int PSABBATON = 6;

	int year;
	int month;
	int day;
	

	public int getDayOfWeek(){
		return RataDie.dayOfWeek(getRDFromCalendar());
	}
	
	public String getStringForDay(){
		switch(getDayOfWeek()){
		case 0: return "Tkyriake";
		case 1: return "Pesnau";
		case 2: return "Pshoment";
		case 3: return "Peftoou";
		case 4: return "Ptiou";
		case 5: return "Psoou";
		case 6: return "Psabbaton";
		}
		return null;
	}
	
	public static boolean isYearLeap(int year){
		return (year%4<0)?(year%4==-1):(year%4==3);
	}
	
	public boolean isYearLeap(){
		return isYearLeap(year);
	}
	
	public long getRDFromCalendar() {
		return (long) (EPOCH + 365*(year-1) + 30*(month-1) + day-1 + Math.floor(year/4.0));
	}

	
	public static CopticCalendar getCalendarFromRD(long rd){
		int year = (int) Math.floor((4*(rd-EPOCH)+1463)/1461.0);
		CopticCalendar cc = new CopticCalendar(year, 1, 1);
		int month = (int) (1+Math.floor((rd-cc.getRDFromCalendar())/30.0));
		cc.setMonth(month);
		int day = (int) (rd+1-cc.getRDFromCalendar());
		cc.setDay(day);
		return cc;
	}

	public CopticCalendar(int year, int month, int day) {
		super();
		this.year = year;
		this.month = month;
		this.day = day;
	}

	public final int getYear() {
		return year;
	}

	public final void setYear(int year) {
		this.year = year;
	}

	public final int getMonth() {
		return month;
	}

	public final void setMonth(int month) {
		this.month = month;
	}

	public final int getDay() {
		return day;
	}

	public final void setDay(int day) {
		this.day = day;
	}
	
	

}
